package com.zqxq.lottery.service.user.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zqxq.common.utils.StrUtils;
import com.zqxq.lottery.config.YmlConfig;
import com.zqxq.lottery.entity.bo.user.UserCashBO;
import com.zqxq.lottery.entity.bo.user.UserCashSearchBO;
import com.zqxq.lottery.entity.o2o.user.UserCashO2O;
import com.zqxq.lottery.entity.po.user.UserCashPO;
import com.zqxq.lottery.entity.vo.expert.CommissionVO;
import com.zqxq.lottery.entity.vo.user.UserCashVO;
import com.zqxq.lottery.mapper.user.UserCashMapper;
import com.zqxq.lottery.service.user.IUserCashService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;


@Service
@Slf4j
public class UserCashServiceImpl extends ServiceImpl<UserCashMapper, UserCashPO> implements IUserCashService {

    @Autowired
    private YmlConfig ymlConfig;

    @Override
    public Page queryPage(UserCashBO search) throws Exception {
        Page page = new Page(search.getPageNo(), search.getPageSize());
        List<UserCashVO> list = baseMapper.queryPage(page, search);
        for(UserCashVO cash : list){
            switch (cash.getType()){
                case "1":
                  cash.setBehavior("购买趣豆");
                  break;
                case "3":
                    cash.setBehavior("竞猜预测");
                    break;
                case "4":
                    cash.setBehavior("竞猜预测");
                    break;
                case "5":
                    cash.setBehavior("竞猜预测");
                    break;
                case "6":
                    cash.setBehavior("竞猜预测");
                    break;
                case "7":
                    cash.setBehavior("充值趣豆");
                    break;
                case "8":
                    cash.setBehavior("抽钻石");
                    break;
                case "9":
                    cash.setBehavior("抽钻石");
                    break;
                case "12":
                    cash.setBehavior("资讯打赏");
                    break;
            }
        }
        page.setRecords(list);
        return page;
    }

    @Override
    public List<UserCashVO> query(UserCashSearchBO search) throws Exception {
        List<UserCashVO> list = baseMapper.queryPage(search);
        for(UserCashVO cash : list){
            switch (cash.getType()){
                case "1":
                    cash.setBehavior("购买趣豆");
                    break;
                case "3":
                    cash.setBehavior("足球竞猜");
                    break;
                case "4":
                    cash.setBehavior("足球竞猜");
                    break;
                case "5":
                    cash.setBehavior("足球竞猜");
                    break;
                case "6":
                    cash.setBehavior("足球竞猜");
                    break;
                case "7":
                    cash.setBehavior("充值趣豆");
                    break;
                case "8":
                    cash.setBehavior("抽钻石");
                    break;
                case "9":
                    cash.setBehavior("抽钻石");
                    break;
            }
        }
        return list;
    }
    @Override
    public Page queryCommissionPage(UserCashBO search) throws Exception {
        Page page = new Page(search.getPageNo(), search.getPageSize());
        List<UserCashVO> list = baseMapper.queryCommissionPage(page, search);
        page.setRecords(list);
        return page;
    }

    @Override
    public Page queryPageCZ(UserCashBO search) throws Exception {
        Page page = new Page(search.getPageNo(), search.getPageSize());
        if(!StringUtils.isEmpty(search.getRealNameOrMobile())){
            search.setRealNameOrMobile("%"+search.getRealNameOrMobile()+"%");
        }
        List<UserCashVO> list = baseMapper.queryPageCZ(page, search);
        page.setRecords(list);
        return page;
    }

    @Override
    public Page queryPageTX(UserCashBO search) throws Exception {
        Page page = new Page(search.getPageNo(), search.getPageSize());
        List<UserCashVO> list = baseMapper.queryPageTX(page, search);
        page.setRecords(list);
        return page;
    }

    @Override
    public UserCashVO save(UserCashVO vo) throws Exception {
        UserCashPO po = UserCashO2O.toPO(vo);
        if (StrUtils.isEmpty(vo.getId())) {
            Long id = ymlConfig.getPkId();
            vo.setId(id + "");
            po.setId(id);
            baseMapper.insert(po);
        } else {
            baseMapper.updateById(po);
        }
        return vo;
    }

    @Override
    public UserCashVO getTX(Long id) throws Exception {
        return baseMapper.getTX(id);
    }

    @Override
    public Integer getDrawCashCount(Long userId) {
        return baseMapper.getDrawCashCount(userId);
    }

    @Override
    public CommissionVO commissionInfo(Long user_id) {
        return baseMapper.commissionInfo(user_id);
    }
}
